package top.ajunnihao.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * <p>
 * Swagger 配置
 * </p>
 */
@Configuration
@EnableSwagger2 // 开启 Swagger
public class SwaggerConfig {

    /**
     * 配置 Swagger 实例
     */
    @Bean
    public Docket docket() {
        String basePackage = "top.ajunnihao.core";
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("阿骏")
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage)) // 要扫描的 controller 包
                .paths(PathSelectors.any()) // 过滤请求路径，ang()表示扫描所有请求
                .build();
    }

    /**
     * 配置 Swagger apiInfo
     */
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("阿骏的Swagger API文档")
                .description("阿骏的 API 文档")
                .version("1.0.0")
                .termsOfServiceUrl("http://ajunnihao.top/")
                .contact(new Contact("阿骏", "http://ajunnihao.top/", "1241088536@qq.com"))
                .build();
    }

}
